package mgt.pages

class ApiDefinitionCreatePage extends geb.Page {
    static url = "/apiDefinition/create"

    static content = {
        apiGroupSelect(wait: true) { $("#apiGroup") }

        nameField(wait: true) { $("#name") }
        descriptionField(wait: true) { $("#description") }

        requestPathField(wait: true) { $("#requestPath") }

        backendURIField(wait: true) { $("#backendURI") }
        backendPathField(wait: true) { $("#backendPath") }
        backendTiemoutField(wait: true) { $("#backendTimeout") }

        createButton(to: ApiDefinitionShowPage) { $(".save") }
    }

    ApiDefinitionShowPage createApiDefinition(String apiGroupName, String name, String description, String requestPath, String backendURI, String backendPath, Long backendTimeout) {
        apiGroupSelect.value(apiGroupName)
        nameField.value(name)
        descriptionField.value(description)
        requestPathField.value(requestPath)
        backendURIField.value(backendURI)
        backendPathField.value(backendPath)
        backendTiemoutField.value(backendTimeout as String)

        createButton.click()

        return browser.page
    }
}